﻿CREATE TABLE [dbo].[aspnet_Applications] (
    [ApplicationName]        NVARCHAR (256)   NOT NULL,
    [LoweredApplicationName] NVARCHAR (256)   NOT NULL,
    [ApplicationId]          UNIQUEIDENTIFIER CONSTRAINT [DF__aspnet_Ap__Appli__6C4EE43C] DEFAULT (newid()) NOT NULL,
    [Description]            NVARCHAR (256)   NULL,
    [System]                 BIT              CONSTRAINT [DF_aspnet_Applications_System] DEFAULT ((0)) NULL,
    [IDIntern]               VARCHAR (50)     CONSTRAINT [DF_aspnet_Applications_IDIntern] DEFAULT ((0)) NULL,
    [MenuName]               VARCHAR (50)     NULL,
    [NumeDLL]                VARCHAR (100)    NULL,
    CONSTRAINT [PK__aspnet_Applicati__69727791] PRIMARY KEY NONCLUSTERED ([ApplicationId] ASC),
    CONSTRAINT [UQ__aspnet_Applicati__6A669BCA] UNIQUE NONCLUSTERED ([LoweredApplicationName] ASC),
    CONSTRAINT [UQ__aspnet_Applicati__6B5AC003] UNIQUE NONCLUSTERED ([ApplicationName] ASC)
);


GO
CREATE CLUSTERED INDEX [aspnet_Applications_Index]
    ON [dbo].[aspnet_Applications]([LoweredApplicationName] ASC);


GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER aspnet_ApplicationDelete
   ON  dbo.aspnet_Applications
   AFTER DELETE
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @deSters smallint
	SET @deSters = 0
	SELECT @deSters = Count(*) from [Deleted] WHERE [System] = 1
	IF @deSters<>0
		GOTO Error1

    GOTO Gata
	Error1:
		RAISERROR ('Aplicatia nu poate fi stearsa deoarece apartine sistemului!', 16, 1)
		ROLLBACK TRANSACTION
	Gata:

END